{%include file="index.header.tpl.php"%}
{%include file="index.left.tpl.php"%}
  <!--主要内容开始-->
  <div class="content-wrapper">
    <section class="content">
      <div class="row">
	  <form name="form1" action="" method="get">
        <section class="col-sm-3 connectedSortable" style="padding-right:0px;">
               <div class="box box-solid">
                  <div class="box-header with-border" id="boring">
                       <div class="form-group">
                                <select class="form-control" style="padding:0;" id="semester_id" name="semester_id">
                                      <option value="0">请选择学年学期</option>
									  {%foreach from=$semester_lists key=key item=value%}
                                      <option value="{%$value.semester_id%}" {%if $value.semester_id==$semester_data.semester_id%}selected{%/if%}>{%$value.semester_name%}</option>
									  {%/foreach%}	

                                </select>					  
                        </div>
                        <div class="form-group">
                                <select class="form-control grades" style="padding:0;" name="exam_id"  id="exam_name">
                                      <option value="0">-请选择-</option>
										{%if $exam_data!=""%}
                                      <option value="{%$exam_data.exam_id%}" selected>{%$exam_data.exam_name%}</option>
										{%/if%}									  
                                </select>					  
                        </div>
                        <div class="form-group">
                                <select class="form-control classfy" style="padding:0;" onChange="grade_change()" name="grade_id" id="grade_id"> 
                                      <option>请选择年级</option>
									  {%foreach from=$class_lists key=key item=value%}
                                      <option value="{%$key%}" {%if $key==$grade_data.grade_id%}selected{%/if%}>{%$value.grade_name%}</option>
									  {%/foreach%}
                                </select>					  
                        </div>
						{%foreach from=$class_lists key=key item=value%}
                        <div class="form-group all" style="height:100px; overflow-y:scroll; {%if $key==$grade_data.grade_id%}display:block{%else%}display:none{%/if%}" id="cg_{%$key%}" >
                               <label><input type="checkbox" name="allChecked1" id="allChecked" onclick="DoCheck()"> 全选 </label><br/>
							   {%foreach from=$value.class key=k item=v%}
                               <label><input type="checkbox" name="class_ids[]" value="{%$v.class_id%}" {%if $v.check=='1'%}checked{%/if%}> {%$v.class_name%} </label><br/>
							   {%/foreach%}					  
                        </div>
						{%/foreach%}
                    </div>
                </div><!--box box-solid-->
                 <div class="box box-solid">
                      <div class="box-header with-border">
                           <label>分数段</label>
                            <div class="form-group">
                                  <table class="table" id="plus">
                                       <tr>
                                            <td>选择</td>
                                            <td>最高分</td>
                                            <td>最低分</td>
                                       </tr>
									   {%foreach from=$range key=key item=value%}
                                       <tr>
										<td><input type='checkbox' name='chkArr' id='chkArr{%$key%}' style='width:20px' /></td>
										<td><input type='text' name='range_max_{%$key%}' value="{%$value.max%}" id='nodeper{%$key%}' style='width:40px' /></td>
										<td><input type='text' name='range_min_{%$key%}' value="{%$value.min%}" id='nodename{%$key%}' style='width:40px' /></td>
                                       </tr>									   
									   {%/foreach%}
                                </table>
                                <input type="button" onclick="addNewRow();" value="添加分数段" />
                                <a href="#" onclick="removeRow();"> 删除</a>     				  
                            </div>
                        </div>
                </div><!--box box-solid-->
                 <div class="box box-solid">
                      <div class="box-header with-border">
                           <label class="col-sm-2" style="padding:0">科目</label>
                           <div class="col-sm-9 form-group" style="height:80px; overflow-y:scroll; margin-bottom:30px;">
                                   <label><input type="radio" name="subject_id" value="0"  {%if $subject_id=="0"%}checked{%/if%}> 总分</label><br/>
									{%foreach from=$subject_lists key=key item=value%}
                                   <label><input type="radio" name="subject_id" value="{%$value.subject_id%}" {%if $value.subject_id==$subject_id%}checked{%/if%}> {%$value.subject_name%}</label><br/>
									{%/foreach%}
                            </div>
                            <div style="clear:both;">
							<input type="hidden" name="a" value="score.diy">
                            <button type="submit" class="btn btn-primary btn-sm">确定查询</button>
                            </div>
                        </div>
                </div><!--box box-solid-->
        </section>
		</form>
        <section class="col-sm-9 connectedSortable">
         <div class="box box-default box-solid">
                <div class="box-header with-border">
                    <span class="fa fa-list" style="float:left; font-size:18px; padding-top:3px; color:#3c8dbc;" ></span>
                    <p class="box-title">分数段自定义查询列表</p>
                </div>
                <div class="box-body">
                     <h4 class="text-center">{%$semester_data.semester_name%}{%$exam_data.exam_name%}{%$grade_data.grade_name%}{%$subject_name%}自定义分数段查询</h4>
                       <table class="table table-bordered"  id="mytable">
                                    <tr>
                                        <td>年级名称</td>
                                        <td>班级名称</td>
										{%foreach from=$range key=key item=value%}
										<td>{%$value.max%}-{%$value.min%}分</td>
										{%/foreach%}
                                    </tr>
									{%foreach from=$data_lists key=key item=value%}
                                    <tr>
                                        <td>{%$grade_data.grade_name%}</td>
                                        <td>{%$value.class_name%}</td>
										{%foreach from=$value.score key=k item=v%}
										<td>{%$v%}</td>
										{%/foreach%}
                                    </tr>
									{%/foreach%}	 	
                        </table>  
				</div><!--box-body -->
                <div class="box-footer">
 
                </div>
           </div><!--box box-default box-solid-->
         </section>   
        </div><!--row-->
    </section>
 </div>
  <!--主要内容结束-->
{%include file="index.footer.tpl.php"%}
 <script>
    function grade_change()
           {
			$(".all").hide();
            var val = $("#grade_id").val();
			$("#cg_"+val).show();
           }
		   	   
 	function DoCheck()
		{
			var ch = document.getElementsByName("class_ids[]");
			if(document.getElementsByName("allChecked")[0].checked == true)
		   {
				for(var i=0;i<ch.length;i++)
				{
				ch[i].checked=true;
				}
			}else{
				for(var i=0;i<ch.length;i++)
				{
				ch[i].checked=false;
				}
			}
		}

		  function addNewRow(){
		   var tabObj=document.getElementById("plus");//获取添加数据的表格
		   var rowsNum = tabObj.rows.length;  //获取当前行数
		   var colsNum=tabObj.rows[rowsNum-1].cells.length;//获取行的列数
		   var myNewRow = tabObj.insertRow(rowsNum);//插入新行
		   var newTdObj1=myNewRow.insertCell(0);
		   newTdObj1.innerHTML="<input type='checkbox' name='chkArr' id='chkArr"+rowsNum+"' style='width:20px' />";
		   var newTdObj2=myNewRow.insertCell(1);
		   newTdObj2.innerHTML="<input type='text' name='range_max_"+rowsNum+"' id='nodeper"+rowsNum+"' style='width:40px' />";
		   var newTdObj3=myNewRow.insertCell(2);
		   newTdObj3.innerHTML="<input type='text' name='range_min_"+rowsNum+"' id='nodename"+rowsNum+"' style='width:40px' />";
		  }
		//窗口表格删除一行
		  function removeRow(){
		   var chkObj=document.getElementsByName("chkArr");
		   var tabObj=document.getElementById("plus");
		   for(var k=0;k<chkObj.length;k++){
			if(chkObj[k].checked){
			 tabObj.deleteRow(k+1);
			 k=-1;
			}
		   }
		  }
</script>
  <script type="text/javascript">
        $(document).ready(function () {
             $("#semester_id").change(function () {		
                 if ($(this).val() == "-1") {
					$("#industr").remove(); return; 
					}
                else {
			var timestamp = new Date().getTime();
			$.ajax({
			url:"index.php?a=exam.listBySemesterJson",
			type:"get",
			data: "semester_id=" + $("#semester_id").find("option:selected").val() + "&timestamp=" + timestamp,
			dataType:"json",
			success:function(msg){
                             var industr = "";
                             $.each(msg, function (n, v) {
                                industr += ("<option value=\"" + n + "\">" + v);
                                industr += ("</option>");
                            });
                             $("#exam_name").html(industr);			   			   
			}
			});					
                 }

            });

        });
</script>
<script>
    //checbox全选  
    function DoCheck()
    {
        var ch=document.getElementsByName("class_ids[]");
        if(document.getElementsByName("allChecked")[0].checked==true)
        {
            for(var i=0;i<ch.length;i++)
            {
                ch[i].checked=true;
            }
        }else{
            for(var i=0;i<ch.length;i++)
            {
                ch[i].checked=false;
            }
        }
    }
</script>
